#include "NumberSpeller.h"

namespace ZioUtils
{

	std::string NumberSpeller::m_NumberStrings[] = {
		"",					// Useful
		"One",
		"Two",
		"Three",
		"Four",
		"Five",
		"Six",
		"Seven",
		"Eight",
		"Nine",
		"Ten",
		"Eleven",
		"Twelve",
		"Thirteen",
		"Fourteen",
		"Fifteen",
		"Sixteen",
		"Seventeen",
		"Eighteen",
		"Nineteen",
		"Twenty",			// 20
		"Thirty",			// 21
		"Forty",			// 22
		"Fifty",			// 23
		"Sixty",			// 24
		"Seventy",			// 25
		"Eighty",			// 26
		"Ninety",			// 27
		"Hundred",			// 28
		"Thousand"			// 29
	};

	NumberSpeller::NumberSpeller()
	{
	}

	NumberSpeller::~NumberSpeller()
	{
	}

	using namespace std;
	string NumberSpeller::SpellNumber(UInt32 number)
	{
		if (number < 100)
		{
			return SpellTens(number);
		}
		else if (number >= 100 && number < 1000)
		{
			return SpellHundreds(number);
		}
		else if (number >= 1000)
		{
			return "One" + m_NumberStrings[29];
		}
		else
		{
			return "";
		}
	}

	string NumberSpeller::SpellHundreds(UInt32 number)
	{
		UInt32 hundreds = number / 100;
		UInt32 tens = number % 100;

		string hString = m_NumberStrings[hundreds] + "Hundred";
		string tString = SpellTens(tens);

		string stringNumber = hString;
		if (tens > 0)
			return hString + "And" + tString;
		else
			return hString;
	}

	string NumberSpeller::SpellTens(UInt32 number)
	{
		if (number <= 20)
		{
			return m_NumberStrings[number];
		}
		else if (number > 20 && number < 100)
		{
			UInt32 decNumber = 20 + ((number - 20) / 10);
			string decString = m_NumberStrings[decNumber];

			UInt32 unitNumber = (number - 20) % 10;
			string unitString = m_NumberStrings[unitNumber];

			return decString + unitString;
		}
		else
		{
			return "";
		}

		//ugasoft: ...and what if number>100? please remove this warning C4715 "not all control paths return a value...
		// :)
	}

}

